﻿<?php

final class ConectaMysql{

	private $conexao;
	private $query;
	private $resultQuery;
	
    function __construct(){
  	
		try{
        
			$this->conexao = new PDO('mysql:host=localhost;port=3306;dbname=phpsupport','root','');
			$this->conexao->query("SET NAMES 'utf8'") ;
			$this->conexao->query("SET character_set_connection=utf8"); 
			$this->conexao->query("SET character_set_client=utf8"); 
			$this->conexao->query("SET character_set_results=utf8"); 
			
        
		}catch(PDOException $erro){
            
			print "Erro: ".$erro->getMessage()."\n";
        
		}
   	
	}
     
    public function executaQuery($query){
		
        try{
        	$this->query = $query;                
        	$this->resultQuery = $this->conexao->query($this->query);
			$this->conexao->query("commit");
			
			return $this->resultQuery;
		
		}catch(PDOException $erro){
            print "Erro: ".$erro->getMessage()."\n";
        }
		
	}
	   
	
	public function rowCount($query){
		
		try{
        	$this->query = $query;                
        	$this->resultQuery = $this->conexao->query($this->query);
			$rowCount = $this->resultQuery->rowCount();
			
			return $rowCount;
		
		}catch(PDOException $erro){
            print "Erro: ".$erro->getMessage()."\n";
        }
		
		
	}
	
	
	public function encerraConexao(){
    	try{
        	$this->conexao = null;
		
		}catch(PDOException $erro){
        	print "Erro: ".$erro->getMessage()."\n";
        }
	    
	}
}

 
?>